class Solution {
private:
    struct cmp{
        bool operator () (vector<int>& a, vector<int>& b){
            if(a[2] != b[2]) return a[2] > b[2];
            return a[0] > b[0];
            
        }
    };

    bool static cmp_1(vector<int>& a, vector<int>& b){
        if(a[1] != b[1])return a[1] < b[1];
        else if(a[2] != b[2])return a[2] < b[2];
        return a[0] < b[0];
        
    }
public:
    vector<int> getOrder(vector<vector<int>>& tasks) {
        int time = 0;
        vector<vector<int>>tasks1;
        for(int i = 0; i < tasks.size(); i++){
            vector<int>temp;
            temp.push_back(i);
            temp.push_back(tasks[i][0]);
            temp.push_back(tasks[i][1]);
            tasks1.push_back(temp);
        }
        priority_queue<vector<int>, vector<vector<int>> , cmp> p;
        sort(tasks1.begin(), tasks1.end(), cmp_1);
        vector<int> ans;
        for(int i = 0; i < tasks1.size(); i++){
            vector<int> temp;
            temp.push_back(tasks1[i][0]);
            temp.push_back(tasks1[i][1]);
            temp.push_back(tasks1[i][2]);
            if(p.empty()){
                p.push(temp);
                time = temp[1];
            }
            else{
                vector<int> temp_top = p.top();
                time += temp_top[2];
                ans.push_back(temp_top[0]);
                p.pop();
                while(temp[1] <= time){
                    p.push(temp);
                    i++;
                    if(i == tasks1.size())break;
                    temp.clear();
                    temp.push_back(tasks1[i][0]);
                    temp.push_back(tasks1[i][1]);
                    temp.push_back(tasks1[i][2]);
                }
                i--;
            }
        }
        while(!p.empty()){
            ans.push_back(p.top()[0]);
            p.pop();
        }
        return ans;
    }
};
//2021.4.18
